<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/8/9
 * Time: 21:20
 */

namespace app\admin\controller;
use app\home\model\OaStFw;
use app\home\model\OaStudent;
use app\home\model\ZsbOaStFw;
use app\home\model\ZsbOaStudent;
use think\Db;
/**
 * Class Approve
 * @package app\admin\controller
 * 认证管理
 */
class Approve extends Admin
{
    /**
     * @return mixed
     * 首页
     */
    public function index(){
        $vip = input('vip');
        $name = input('name');
        $type = input('type');
        $map = [];
        if ($name){
            $vipp = iconv("utf-8","gbk//TRANSLIT",$name);
            $map = ['st_name' => ['like', "%$vipp%"]];
        }
        if ($vip){
            if (preg_match('/^[\x{4e00}-\x{9fa5}]+$/u',$vip)){
                return $this->error('请输入VIP');
            }
            $map = ['order_id' => ['like', "%$vip%"]];
        }
        $Student = new OaStFw();
        $Students = new ZsbOaStFw();
        if (empty($type) || $type == 1){  // 考研
            $list = $Student
                ->where($map)
                ->field('id,st_name,s_id,order_id,product,ins_time,1 as type')
                ->order('ins_time','desc')
                ->paginate(10,false,['query' => ['type' => $type,'vip' => $vip,'name' => $name]]);
        }elseif ($type == 2){  // 专升本
            $list = $Students
                ->where($map)
                ->field('id,s_id,st_name,order_id,product,ins_time,2 as type')
                ->order('up_time','desc')
                ->paginate(10,false,['query' => ['type' => $type,'vip' => $vip,'name' => $name]]);
        }
        $this->assign('list',$list);
        $this->assign('type',$type);
        return $this->fetch();
    }
    /**
     * 操作
     */
    public function play(){
        $type = input('type/d');  // 类型  1 考研 2 专升本
        $id = input('id/d'); // 编号
        if (empty($id)){
            return $this->error('系统参数错误');
        }
        $tel = input('tel');  // 手机号
        if ($type == 1){
            // 考研
            $res = OaStudent::where('id',$id)->update(['tel' => $tel]);
        }else{
            // 专升本
            $res = ZsbOaStudent::where('id',$id)->update(['tel' => $tel]);
        }
        if ($res){
            return $this->success('操作成功');
        }else{
            return $this->error('操作失败');
        }
    }
}